package com.example.controller;

import com.example.entity.po.Classroom;
import com.example.entity.po.Honor;
import com.example.service.HonorService;
import com.example.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HonorController {
    @Autowired
    private HonorService honorService;

    //查询荣誉
    @GetMapping("/queryHonor")
    public ResultUtils queryHonor(){
        List<Honor> list= honorService.queryHonor();
        if (list.size()==0){
            return ResultUtils.Failure("查询荣誉失败",null);
        }else{
            return ResultUtils.Successful("查询荣誉信息成功",list);
        }
    }

    //添加荣誉
    @PostMapping("/addHonor")
    public ResultUtils addHonor(@RequestBody Honor honor){
        int res= honorService.addHonor(honor);
        if (res==0){
            return ResultUtils.Failure("添加询荣誉失败",null);
        }else{
            return ResultUtils.Successful("添加荣誉信息成功",null);
        }
    }

    //删除荣誉
    @PostMapping("/deleteHonor")
    public ResultUtils deleteHonor(int honorId){
        int res= honorService.deleteHonor(honorId);
        if (res==0){
            return ResultUtils.Failure("删除荣誉失败",null);
        }else{
            return ResultUtils.Successful("删除荣誉信息成功",null);
        }
    }

    //修改荣誉
    @PostMapping("/updateHonor")
    public ResultUtils updateHonor(@RequestBody Honor honor){
        int res= honorService.updateHonor(honor);
        if (res==0){
            return ResultUtils.Failure("修改询荣誉失败",null);
        }else{
            return ResultUtils.Successful("修改荣誉信息成功",null);
        }
    }

    //对荣誉进行模糊查询
    @PostMapping("/fuzzyHonor")
    public ResultUtils fuzzyHonor(String honorContent){
        List<Honor> honorList= honorService.fuzzyHonor(honorContent);
        if (honorList.size()==0){
            return ResultUtils.Failure("搜索荣誉失败或无该荣誉",null);
        }else {
            return ResultUtils.Successful("搜索荣誉成功",honorList);
        }
    }
}
